package com.palmshop.online.alipay.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Map;

import org.dom4j.DocumentException;

import com.palmshop.online.alipay.config.AlipayConfig;
import com.palmshop.online.alipay.util.AlipaySubmit;

/**
 * AlipayService <br>
 * alipay服务类
 * <p>
 * C
 * <p>
 * 
 * @author kongjp@c-platform.com
 * @version 1.0.0
 */
public class AlipayService {

	private static final String ALIPAY_GATEWAY_NEW = "https://mapi.alipay.com/gateway.do?";

	/**
	 * 支付包即时到账接口
	 * 
	 * @param sParaTemp
	 * @return
	 * @throws IOException
	 * @throws DocumentException
	 * @throws MalformedURLException
	 */
	public static String create_direct_pay_by_user(Map<String, String> sParaTemp,Map<String,String>params)
			throws MalformedURLException, DocumentException, IOException {
		
		
		AlipayConfig.key="rwmc66qfkzz79v814o7h195imfx9i9zh";
		
		

		// sParaTemp.put("defaultbank", AlipayConfig.bankCode);
		// 付款方式 【默认直接支付】
		sParaTemp.put("paymethod", "directPay");
		// 客户端地址
		sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
		// 商品展示地址
		sParaTemp.put("show_url", AlipayConfig.show_url);
		// 支付方式
		sParaTemp.put("payment_type", AlipayConfig.payment_type);
		// 防钓鱼时间戳
		sParaTemp.put("anti_phishing_key", AlipaySubmit.query_timestamp());
		// 调用的接口名字
		sParaTemp.put("service", AlipayConfig.service);
		// 合作者身份ID
		sParaTemp.put("partner", AlipayConfig.partner);  //!!!!!!!!!!!!!!!!!!!!!!!!!!!
		
//		sParaTemp.put("partner", params.get("shopPartner"));//查询获取!!!!!!!!!!!!!!!!!!
		// 返回界面
		sParaTemp.put("return_url", AlipayConfig.return_url);
		// 异步通知
		
		sParaTemp.put("notify_url", AlipayConfig.notify_url);
		// 卖家支付宝账号
		sParaTemp.put("seller_email", AlipayConfig.seller_email);
		
	//	sParaTemp.put("seller_email", params.get("shopSellerEmail"));//查询获取
		// 字符编码格式
		sParaTemp.put("_input_charset", AlipayConfig.input_charset);
		System.err.println(sParaTemp);
		String strButtonName = "确认";
		return AlipaySubmit.buildForm(sParaTemp, ALIPAY_GATEWAY_NEW, "post",
				strButtonName);
	}
}
